#include "popupdialog.h"
#include "ui_popupdialog.h"

PopupDialog::PopupDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::PopupDialog)
{
    ui->setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_DeleteOnClose);

    m_cPopFlashTimer = new QTimer(this);
    m_cPopFlashTimer->setInterval(800);
    connect(m_cPopFlashTimer,SIGNAL(timeout()),this,SLOT(slotFlash()));
    m_xflashflag = false;
}

PopupDialog::~PopupDialog()
{
    delete ui;
}

void PopupDialog::on_Btn_Confirm_pressed()
{
    done(1);
}

void PopupDialog::on_Btn_Cancel_pressed()
{
    done(0);
}

void PopupDialog::setPopupText(QString str)
{
    ui->popupText->setText(str);
}

void PopupDialog::setPopupFlash(bool xflash)
{
    if(xflash)
        m_cPopFlashTimer->start();
    else
    {
        m_cPopFlashTimer->stop();
        ui->frame->setStyleSheet("#frame{background-color:rgb(0,0,0);border:6px inset rgb(255,255,255);}");
    }
}

void PopupDialog::slotFlash()
{
    if(!m_xflashflag)
        ui->frame->setStyleSheet("#frame{background-color:rgb(255,0,0);border:6px inset rgb(255,255,255);}");
    else
        ui->frame->setStyleSheet("#frame{background-color:rgb(0,0,0);border:6px inset rgb(255,255,255);}");
    m_xflashflag = !m_xflashflag;
}
